package com.gxa.meiye.sso.utils;

import lombok.Data;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;

/**
 * @Author: zy
 * @CreateTime: 2022-07-20  14:41
 */
public class SignInUtils {
    @Data
    static
    class SignIn{
        private Date signInDay;

        public SignIn(){

        }

        public SignIn(String day) throws ParseException {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            signInDay = sdf.parse(day);
        }
    }
    public int getContinuousSignInDay(List<LocalDateTime> signInList) {
        //continuousDay 连续签到数
        int continuousDay = 1;
        boolean todaySignIn = false;
       // Date today = new Date();
        LocalDateTime now = LocalDateTime.now();
        int year = now.getYear();
        int dayOfYear = now.getDayOfYear();
        System.out.println(year);
        System.out.println(dayOfYear);


        System.out.println();
        for (int i = 0; i < signInList.size(); i++) {
            LocalDateTime localDateTime = signInList.get(i);
             //localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
            //Date from = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());

            localDateTime.getMonth();
            localDateTime.getDayOfMonth();


            //int intervalDay = distanceDay(today, from);
            int intervalDay=1;
            //当天签到
            if (intervalDay == 0 && i == 0) {
                todaySignIn = true;
            }
            else if (intervalDay == continuousDay) {
                continuousDay++;
            }else {
                //不连续，终止判断
                break;
            }
        }

        if (!todaySignIn) {
            continuousDay--;
        }
        return continuousDay;
    }

   public int distanceDay(Date largeDay, Date smallDay) {
        int day = (int) ((largeDay.getTime() - smallDay.getTime()) / (1000 * 60 * 60 * 24));
        return day;
    }

}
